package com.perselab.recipe.service;

import java.io.Serializable;
import java.util.List;

import com.perselab.recipe.dao.GenericDao;
import com.perselab.recipe.model.Model;

/**
 * Base class for Business Services - use this class for utility methods and
 * generic CRUD methods.
 * @param <T> entity type
 * @param <PK> primary key type
 */
public abstract class ManagerImpl<T extends Model<PK>, PK extends Serializable> implements Manager<T, PK> {
	public abstract GenericDao<T, PK> getDao();
	
	/**
	 * {@inheritDoc}
	 */
	public List<T> getAll() {
		return getDao().getAll();
	}

	/**
	 * {@inheritDoc}
	 */
	public T get(PK id) {
		return getDao().get(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public T save(T o) {
		return getDao().save(o);
	}

	/**
	 * {@inheritDoc}
	 */
	public void remove(T o, PK id) {
		getDao().remove(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public void remove(PK id) {
		getDao().remove(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public void remove(T o) {
		getDao().remove(o.getId());		
	}
}
